package com.wisdudu.blank.support.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

/**
 * 声音进度条
 * Created by ypp on 2016/10/28.
 */
public class CustomCircleProgressView extends View {

    private int mMaxProgress = 100;
    private int mProgress = 0;
    private final int mCircleLineStrokeWidth = 24;

    public CustomCircleProgressView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int width = this.getWidth();
        int height = this.getHeight();

        //初始化 画笔 背景
        Paint paint = new Paint();
        paint.setColor(Color.TRANSPARENT);
        paint.setAntiAlias(true);
        canvas.drawColor(Color.TRANSPARENT);
//        Rect targetRect = new Rect(0, height / 2 - 30, 0, 100);
//        canvas.drawRect(targetRect, paint);

        //进度0/3 粗字体
//        paint = new Paint();
//        paint.setAntiAlias(true);
//        paint.setTextAlign(Paint.Align.LEFT);
//        paint.setTextSize(DensityUtil.sp2px(context, 60)); //设置字体大小，int型，如12
//        paint.setColor(Color.WHITE);
//        Rect rect = new Rect(0, 0, width, height / 2);
//        canvas.drawText(countStr, rect.centerX() / 2 + 20, rect.bottom - 30, paint);

//        paint.setTextAlign(Paint.Align.CENTER);
//        canvas.drawText(countStr, targetRect.centerX(), baseline, paint);

        //提示语
//        paint = new Paint();
//        paint.setColor(Color.WHITE);
//        paint.setTextAlign(Paint.Align.LEFT);
//        paint.setAntiAlias(true);
//        paint.setTextSize(DensityUtil.sp2px(context, 12)); //设置字体大小，int型，如12
//        rect = new Rect(0, height / 2, width, height / 2);
//        canvas.drawText(text, rect.centerX() / 4, rect.centerY() + 100, paint);
//        canvas.drawText(text1, rect.centerX() / 4, rect.centerY() + 110, paint);

        //最外边大圆环
        paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(Color.WHITE);
        paint.setStrokeWidth(2);
        paint.setStyle(Paint.Style.STROKE);
        RectF rectF = new RectF(0, 0, width, height);
        canvas.drawOval(rectF, paint);

        //第二圈圆环
        paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(Color.WHITE);
        paint.setStrokeWidth(6);
        paint.setStyle(Paint.Style.STROKE);
        rectF = new RectF(mCircleLineStrokeWidth, mCircleLineStrokeWidth, width - mCircleLineStrokeWidth, height - mCircleLineStrokeWidth);
        canvas.drawOval(rectF, paint);

        //进度条白色圆环
        paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(Color.WHITE);
        paint.setStrokeWidth(mCircleLineStrokeWidth);
        paint.setStyle(Paint.Style.STROKE);
        // 位置
        rectF = new RectF();
        rectF.left = mCircleLineStrokeWidth / 2; // 左上角x
        rectF.top = mCircleLineStrokeWidth / 2; // 左上角y
        rectF.right = width - mCircleLineStrokeWidth / 2; // 左下角x
        rectF.bottom = height - mCircleLineStrokeWidth / 2; // 右下角y
        // 绘制圆圈，进度条背景
//        canvas.drawArc(rectF, -90, 360, false, paint);
        canvas.drawArc(rectF, -90, ((float) mProgress / mMaxProgress) * 360, false, paint);
    }

    public void setProgress(int progress) {
        this.mProgress = progress;
//        this.countStr = s;
        this.invalidate();
    }

}
